{include file="../application/admin/view/header.html" /}
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
	<div class="alert kesn_prompt"></div>
</div>
	<!-- <nav class="navbar navbar-default navbar-lg" role="navigation" align="center"> -->
	<button class="btn btn-info kesn_to" data-id="add_policy" data-title="新增文件" data-url="/index.php/admin/policy/save_policy_view">新增<span class="fui-plus btn-tip"></span></button>
	<!-- </nav> -->
	<form class="navbar-form navbar-right" action="index" role="search"  method="get">
	  <div class="form-group">
	    <div class="input-group input-group-rounded">
	      <input class="form-control" id="keyword" name="keyword" type="search" placeholder="请输入文件名">
	      <span class="input-group-btn">
	        <button type="submit" class="btn kesn_search"><span class="fui-search"></span></button>
	      </span>
	    </div>
	  </div>
	</form>

</div><br/>
&nbsp;&nbsp;<br/>
<div></div>
<div class="row">
	<table class="table table-hover">
		<thead>
			<th>ID</th>
			<th class="col-sm-6">文件</th>
			<th>操作</th>
			<th>是否发布</th>
		</thead>
		<tbody>
		{volist name="policy_list" id="policy"}
		<tr class="_item">
				<th scrope="row">{$policy.id}</th>
				<td>{$policy.policy}</td>
				<td><div>
					<a href="#" class="btn btn-primary kesn_to btn-sm" data-id="edit_policy" data-title="编辑文件" data-url="/index.php/admin/policy/save_policy_view?policy_id={$policy.id}">编辑<span class="fui-new btn-tip"></span></a>
					<a href="#" class="btn btn-danger kesn_del btn-sm" data-_id="{$policy.id}" data-_name="{$policy.policy}">删除<span class="fui-cross btn-tip"></span></a>
				</div></td>
				<td>
					<span class="bootstrap-switch-square">
			            <div class="bootstrap-switch bootstrap-switch-wrapper bootstrap-switch-{$policy.if_publish} bootstrap-switch-animate"><div class="bootstrap-switch-container"><span class="bootstrap-switch-handle-on bootstrap-switch-primary">发布</span><label class="bootstrap-switch-label">&nbsp;</label><span class="bootstrap-switch-handle-off bootstrap-switch-default">关闭</span><input type="checkbox" checked="" data-toggle="switch" data-on-label="<i class='fui-check'></i>" data-off-label="<i class='fui-cross'></i>" name="switch-04" id="custom-switch-04"></div></div>
			          </span>
				</td>
		</tr>
		{/volist}
	</tbody>
</div>
	{$page}
</div>
{include file="../application/admin/view/footer.html" /}
<script type="text/javascript">
$('tbody').on('click','.kesn_del',function(){
	var _this = $(this);
	var _id = _this.attr('data-_id');
	var _name = _this.attr('data-_name');
	var _url = 'del_policy';
	var message = '您确实要删除 '+_id+': '+_name+' 吗？';
	kesn_del(_id,_url,message,_this);
});

$('tbody').on('click','.bootstrap-switch',function(){
	var _this = $(this);
	var policy_id = _this.parents('._item').find('th[scrope=row]').html();
	var if_publish ;
	if (_this.hasClass('bootstrap-switch-on')){
		if_publish = '0';
	}else if (_this.hasClass('bootstrap-switch-off')) {
		if_publish= '1';
	}
	$.ajax({
       url: "update_if_publish",    //请求的url地址
	      dataType: "json",   //返回格式为json
	      async: true, //请求是否异步，默认为异步，这也是ajax重要特性
	      data: { "policy_id":policy_id ,"if_publish" : if_publish },    //参数值
	      type: "GET",   //请求方式
	      success: function(data) {
	        if (data.err == '0') {
	        	if (if_publish == '0') {
	        		_this.removeClass('bootstrap-switch-on');
					_this.addClass('bootstrap-switch-off');
	        	}else if(if_publish == '1'){
	        		_this.removeClass('bootstrap-switch-off');
					_this.addClass('bootstrap-switch-on');
	        	}
	        	kesn_prompt('success',data.content);
	        }else{
	        	kesn_prompt('fail',data.content);
	        }
	      }
	});
});
</script>

</footer>
</body>
</html>